<template>
  <div class="login">
    <div class="login-form">
      <h1>灰兔智能管理后台</h1>
      <el-form ref="dataForm" :rules="rules" :model="temp" style="margin: 0 auto">
        <template>
          <el-form-item prop="username">
            <el-input
              v-model="temp.username"
              prefix-icon="el-icon-user-solid"
              placeholder="请输入用户名"
            />
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              type="password"
              v-model="temp.password"
              prefix-icon="el-icon-lock"
              placeholder="请输入密码"
            />
          </el-form-item>
        </template>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="loginForm"
          :loading="loading"
          style="width: 100%; height: 54px; font-size: 14px; font-weight: bold; letter-spacing: 8px"
          >登录</el-button
        >
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      temp: {
        username: '',
        password: ''
      },
      rules: {
        username: [{ required: true, message: '请输入用户名' }],
        password: [{ required: true, message: '请输入密码' }]
      },
      loading: false
    }
  },
  methods: {
    loginForm() {
      const _this = this
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          this.loading = true
          this.$store
            .dispatch('Login', _this.temp)
            .then(() => {
              // _this.$store.dispatch({'user/GetInfo',})
              this.$router.push({ path: '/' })
              this.loading = false
            })
            .catch(() => {
              this.loading = false
            })
          // login(this.temp).then(() => {
          //   this.$parent.$notify({
          //     title: '成功',
          //     message: '登录成功',
          //     type: 'success'
          //   })
          //   this.$router.push({ path: '/dashboard' })
          // })
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.login {
  height: 100vh;
  background: url('../../assets/login_bg.png') no-repeat;
  &-form {
    width: 400px;
    padding-top: 160px;
    margin: 0 auto;
    h1 {
      color: #3e4862;
      font-size: 40px;
      text-align: center;
      margin-bottom: 70px;
    }
  }
}
::v-deep .el-input__inner {
  height: 54px;
  background: #fff;
  border: 1px solid #00000026;
  border-radius: 6px;
  color: #3e4862;
}
</style>
